package day05;

import java.util.Arrays;
import java.util.Random;

public class practice {
    public static void main(String[] args) {
        /*
        //九九乘法表
        for(int num=1;num<=9;num++){
            for(int i=1;i<=num;i++){
                System.out.print(i+"*"+num+"="+i*num+"\t");
            }
            System.out.println();
        }
        //数组声明
        int[] arr = new int[10];
        //初始化
        int[] arr1 = new int[3];
        int[] arr2 = {2,5,8};
        int[] arr3 = new int[]{2,5,8};
        int[] arr4;
        //arr4 = {2,5,8}; //编译错误此方法只能声明并初始化
        arr4 = new int[]{2,5,8};
         */
        /*
        //访问
        int[] arr = new int[3];
        System.out.println(arr.length);
        arr[0] = 100;
        arr[1] = 200;
        arr[2] = 300;
        //arr[4] = 400  数组下标越界
        System.out.println(arr[arr.length-1]);
         */
        /*
        //遍历
        int[] arr = new int[10];
        for(int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        //复制
        int[] a = {10,20,30,40,50};
        a= Arrays.copyOf(a,a.length+1);
        for(int i=0;i<a.length;i++){
            System.out.println(a[i]);
        }
         */
        /*
        int [] a = {10,20,30,40,50};
        int[] b =Arrays.copyOf(a,4);
        for(int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }
         */
        /*
        int[] a = {10,20,30,40,50};
        int[] b = new int[6];
        System.arraycopy(a,1,b,0,4);
        for(int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }

        int[] arr = new int[10];
        for(int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }
        int max = arr[0];
        for(int i=1;i<arr.length;i++){
            if(arr[i]>max){
                max = arr[i];
            }
        }
        System.out.println("最大值为："+max);

        arr = Arrays.copyOf(arr,arr.length+1);
        arr[arr.length-1] = max;
        for(int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
         */
        /*
        //升序排序
        Random rand = new Random();
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = rand.nextInt(100);
            System.out.println(arr[i]);
        }
        Arrays.sort(arr);

        System.out.println("排序后");
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        System.out.println("倒着输出");
        for (int i=arr.length-1;i>=0;i--){
            System.out.println(arr[i]);
        }
        System.out.println("第一个元素为："+arr[0]);
         */
        /*
        //第二遍
        //九九乘法表
        for (int num=1;num<=9;num++){
            for (int i=1;i<=num;i++){
                System.out.println(i+"*"+num+"="+i*num+"\t");
            }
            System.out.println();
        }

        int[] arr = new int[10];
        int[] arr1 = new int[3];
        int[] arr2 = {2,5,8,};
        int[] arr3 = new int[]{2,5,8};
        int[] arr4;
//        arr4 = {2,5,8};
        arr4 = new int[]{2,5,8};

         */
        /*
        int[] arr = new int[3];
        System.out.println(arr.length);
        arr[0] = 100;
        arr[1] = 200;
        arr[2] = 300;
//        arr[3] = 400;
        System.out.println(arr[arr.length-1]);

         */
        /*
        int[] arr = new int[10];
        for (int i=0;i<arr.length;i++){
            arr[i] = (int)(Math.random()*100);
            System.out.println(arr[i]);
        }

         /*
        int[] a = {10,20,30,40,50};
        int[] b = Arrays.copyOf(a,4);
        for (int i=0;i<b.length;i++){
            System.out.println(b[i]);
        }

         */
/*
        int[] a = {10,20,30,40,50};
        int[] b = new int[6];
        System.arraycopy(a,1,b,0,4);
        for (int i=0;i<b.length;i++) {
            System.out.println(b[i]);
        }

 */
/*
            int[] arr = new int[10];
            for (int i=0;i<arr.length;i++){
                arr[i] = (int)(Math.random()*100);
                System.out.println(arr[i]);
            }
            int max = arr[0];
            for (int i=1;i<arr.length;i++){
                if (arr[i]>max){
                    max = arr[i];
                }
            }
            System.out.println("最大值为："+max);

            arr = Arrays.copyOf(arr,arr.length+1);
            arr[arr.length-1] = max;
            for (int i=0;i<arr.length;i++){
                System.out.println(arr[i]);
            }

 */
/*
            Random rand = new Random();
            int[] arr = new int[10];
            for (int i=0;i<arr.length;i++){
                arr[i] = rand.nextInt(100);
                System.out.println(arr[i]);
            }

            Arrays.sort(arr);

        System.out.println("排序后");
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        System.out.println("倒着输出");
        for (int i=arr.length-1;i>=0;i--){
            System.out.println(arr[i]);
        }
        System.out.println("第一个元素为："+arr[0]);

 */
        /*
        //求数字1到100之内，所有偶数的和，并输出
        int num=0;
        for(int i=1;i<=100;i++){
            if(i%2==0){
                num+=i;
            }
        }
        System.out.println(num);

         */
        /*
        //8的阶乘
        int num=1;
        for (int i=1;i<=8;i++){
            num*=i;
        }
        System.out.println(num);

         */
        /*
        for (int i=1;i<15;i+=2){
            for (int j=1;j<=i;j++){
                System.out.print("*");
            }
            System.out.println();
        }

         */
        int[] arr = new int[10];
        Random rand = new Random();
        int max = arr[0];
        int min = arr[0];
        for (int i=1;i<arr.length;i++){
            arr[i] = rand.nextInt(100);
            if (arr[i]>max){
                max = arr[i];
            }
            if (arr[i]<min){
                min = arr[i];
            }
        }
        Arrays.sort(arr);
        for (int i=0;i<arr.length;i++){
            System.out.println(arr[i]);
        }
        System.out.println("最大值为："+max);
        System.out.println("最小值为："+min);

    }
}
